<?php
 /* CAT:Pie charts */
@header('Content-Type: text/html; charset=utf-8');
define("WX_SCALE", "1.5");
define("WX_TOPNUM", "2");
define("WX_FONT", "../fonts/MSYH.ttf");

/* pChart library inclusions */
include("../class/pData.class.php");
include("../class/pDraw.class.php");
include("../class/pPie.class.php");
include("../class/pImage.class.php");

/*会两次进入，原因不明！*/
if(!isset($_POST['dimension'])){
	DEBUGINFO("#Entry chart process...".microtime(true)."\r\n");
	exit();
}

$dimension = $_POST['dimension'];
$chartType = $_POST['chartType'];
$isRegister = $_POST['register']; 
$sex = $_POST['sex']; 
$agetype = $_POST['agetype'];

/*时间过滤*/
$statinfo['start_time'] = str_pad($_POST['statis_from_year'], 4, '0', STR_PAD_LEFT)."-".str_pad($_POST['statis_from_month'], 2, '0', STR_PAD_LEFT)."-".str_pad($_POST['statis_from_day'], 2, '0', STR_PAD_LEFT)." 00:00:00";
$statinfo['end_time'] = str_pad($_POST['statis_to_year'], 4, '0', STR_PAD_LEFT)."-".str_pad($_POST['statis_to_month'], 2, '0', STR_PAD_LEFT)."-".str_pad($_POST['statis_to_day'], 2, '0', STR_PAD_LEFT)." 23:59:59";

/*用户基本信息过滤*/
$userinfo = array();
$userinfo['sex'] = (null==$_POST['sex'])?null:$sex;
if(0 == strcmp("all",$agetype)){
	$userinfo['fromage'] = null;
	$userinfo['toage'] = null;
}else {
	$userinfo['fromage'] = $_POST['fromage'];
	$userinfo['toage'] = $_POST['toage'];
}
$userinfo['start_time'] = str_pad($_POST['join_from_year'], 4, '0', STR_PAD_LEFT)."-".str_pad($_POST['join_from_month'], 2, '0', STR_PAD_LEFT)."-".str_pad($_POST['join_from_day'], 2, '0', STR_PAD_LEFT)." 00:00:00";
$userinfo['end_time'] = str_pad($_POST['join_to_year'], 4, '0', STR_PAD_LEFT)."-".str_pad($_POST['join_to_month'], 2, '0', STR_PAD_LEFT)."-".str_pad($_POST['join_to_day'], 2, '0', STR_PAD_LEFT)." 23:59:59";

if(0 == strcmp('keyword', $dimension))
{
	$result = GetKeywordMaxs(7, $statinfo, $userinfo, $isRegister);

	if(0 == strcmp($chartType,'pie')){
		$scoreList = array(); $labelList = array();
		foreach($result as $key => $value){
			array_push($scoreList, $value);
			array_push($labelList, $key.": ".$value);
		}

		WxDrawPie3D($scoreList, $labelList, "关键字搜索统计");
	}else if(0 == strcmp($chartType,'line')){
		$scoreList = array(); $labelList = array();
		foreach($result as $key => $value){
			array_push($scoreList, $value);
			array_push($labelList, $key);
		}

		WxDrawLine($scoreList,"关键字",$labelList,"搜索频度","关键字分析");
	}else if(0 == strcmp($chartType,'bar')){
		$scoreList = array(); $labelList = array();
		foreach($result as $key => $value){
			array_push($scoreList, $value);
			array_push($labelList, $key);
		}

		WxDrawBar($scoreList,"关键字",$labelList,"搜索频度","关键字分析");
	}
}else if(0 == strcmp('product', $dimension)){
	$result = GetProductMaxs(7, $statinfo, $userinfo);
	$scoreList = array(); $labelList = array();
	foreach($result as $key => $value){
		array_push($scoreList, $value);
		array_push($labelList, $key);
	}
	
	if(0 == strcmp($chartType,'pie')){
		WxDrawPie3D($scoreList, $labelList, "销量统计");
	}else if(0 == strcmp($chartType,'line')){
		WxDrawLine($scoreList, "产品", $labelList, "销量","销量统计");
	}else if(0 == strcmp($chartType,'bar')){	
		WxDrawBar($scoreList, "产品", $labelList, "销量","销量统计");
	}
}else if(0 == strcmp('time', $dimension)){

	$duration['interval_type'] = $_POST['interval_type'];

	$duration['start_time'] = str_pad($_POST['from_year'], 4, '0', STR_PAD_LEFT)."-".str_pad($_POST['from_month'], 2, '0', STR_PAD_LEFT)."-".str_pad($_POST['from_day'], 2, '0', STR_PAD_LEFT)." 00:00:00";
	$duration['end_time']  = str_pad($_POST['to_year'], 4, '0', STR_PAD_LEFT)."-".str_pad($_POST['to_month'], 2, '0', STR_PAD_LEFT)."-".str_pad($_POST['to_day'], 2, '0', STR_PAD_LEFT)." 23:59:59";		

	$result = GetKeywordByTime($duration);
	$scoreList = array(); $labelList = array();
	foreach($result as $key => $value){
		array_push($scoreList, $value);
		array_push($labelList, $key);
	}

	$temp = $$_POST['datavalue'];
	if(0 == strcmp($chartType,'pie')){
		WxDrawPie3D($scoreList, $labelList, "时间统计");
	}else if(0 == strcmp($chartType,'line')){
		WxDrawLine($scoreList, $temp, $labelList, "数量","时间统计");
	}else if(0 == strcmp($chartType,'bar')){	
		WxDrawBar($scoreList, $temp, $labelList, "数量","时间统计");
	}
}

/*返回数组，以keyid为索引，值是array([keytype],[keyword],[search_times])*/
function GetKeyInfo(){
	$con = mysql_connect("127.0.0.1","root","redhat");
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("test", $con);
	mysql_query("set names utf8");

	$temp = "SELECT * FROM keyinfo";
	$db_result = mysql_query($temp);

	$map_result = array();
	while($row = mysql_fetch_array($db_result))
	{
		$map_result[$row['keyid']] = array("keytype"=>$row['keytype'],"keyword"=>$row['keyword'],"search_times"=>$row['search_times']);
	}
	
	mysql_close($con);
	return $map_result;
}

/*统计num个，然后剩余项求和到“其他”*/
/*输出关联数组，每个数组元素形如："汉堡"=>20*/
function GetKeywordMaxs($num, $statinfo, $userinfo, $isRegister){
	$con = mysql_connect("127.0.0.1","root","redhat");
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("test", $con);
	mysql_query("set names utf8");
	
	/*过滤条件（注意两边加空格）*/
	if(!isset($isRegister) || 0==$isRegister){
		$filterstr_register = " ";
	}else{
		$filterstr_register = " AND keytype=".$isRegister." ";
	}
	$filterstr_time = " AND retrieve_time BETWEEN '".$statinfo['start_time']."' AND '".$statinfo['end_time']."' ";
	
	if(null != $userinfo['start_time'] && null != $userinfo['end_time']){
		$filterstr_user = " AND jointime BETWEEN '".$userinfo['start_time']."' AND '".$userinfo['end_time']."' ";
	}
	if(null != $userinfo['fromage'] && null != $userinfo['toage']){
		$filterstr_user = $filterstr_user." AND age BETWEEN ".$userinfo['fromage']." AND ".$userinfo['toage']." ";
	}
	if(1==$userinfo['sex'] || 2==$userinfo['sex']){
		$filterstr_user = $filterstr_user." AND sex=".$userinfo['sex']." ";
	}
	
	$query_str = 
"SELECT keyinfo.keyid, keytype, keyword, COUNT( retrieve.keyid ) counter 
FROM retrieve, keyinfo,customers 
WHERE keyinfo.keyid = retrieve.keyid and customers.openid=retrieve.openid ".$filterstr_register.$filterstr_time.$filterstr_user.
"GROUP BY keyid 
ORDER BY counter DESC";
	$db_result = mysql_query($query_str);
	DEBUGINFO($query_str."\r\n"."Num of result(rows) is ".mysql_num_rows($db_result)."\r\n");

	$result = array();
	$i = 0;
	while($row = mysql_fetch_array($db_result))
	{
		if($i < $num){
			$result[$row['keyword']] = $row['counter'];
		}else{
			$result['其他'] += $row['counter'];
		}
		$i++;
	}

	mysql_close($con);
	return $result;
}


function GetKeywordByTime($duration)
{
	$con = mysql_connect("127.0.0.1","root","redhat");
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("test", $con);
	mysql_query("set names utf8");
	
	/*过滤条件（注意两边加空格）*/
	if(0 == strcmp("hour", $duration['interval_type'])){
		$filterstr_time = " retrieve_time BETWEEN '".$duration['start_time']."' AND '".$duration['end_time']."' ";
		
		$query_str = 
"SELECT count(*) as counter,floor(date_format(retrieve_time,'%k')/2)*2 as hour 
FROM retrieve 
WHERE ".$filterstr_time.
"GROUP BY floor(date_format(retrieve_time,'%k')/2) 
ORDER BY hour ASC";

		$db_result = mysql_query($query_str);
		DEBUGINFO($query_str."\r\n"."Num of result(rows) is ".mysql_num_rows($db_result)."\r\n");
		
		$statistics_map = array();
		while($row = mysql_fetch_array($db_result))
		{
			$statistics_map[$row['hour']] = $row['counter'];
		}
		
		for($i =0; $i<24; $i=$i+2)
		{
			$key = $i."时";
			$result[$key] += $statistics_map[strval($i)];
		}
	}else if(0 == strcmp("weekday", $duration['interval_type'])){
		$weekdays = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
		$filterstr_time = " retrieve_time BETWEEN '".$duration['start_time']."' AND '".$duration['end_time']."' ";
		
		$query_str = 
"SELECT count(*) as counter,date_format(retrieve_time,'%a') as weekday 
FROM retrieve 
WHERE ".$filterstr_time.
"GROUP BY date_format(retrieve_time,'%a')
ORDER BY field( weekday, 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')";

		$db_result = mysql_query($query_str);
		DEBUGINFO($query_str."\r\n"."Num of result(rows) is ".mysql_num_rows($db_result)."\r\n");
		
		$statistics_map = array();
		while($row = mysql_fetch_array($db_result)){
			$statistics_map[$row['weekday']] = $row['counter'];
		}
		
		$result = array();
		foreach($weekdays as $key){
			$result[$key] += $statistics_map[$key];
		}		
	}else if(0 == strcmp("day", $duration['interval_type'])){
		$filterstr_time = " retrieve_time BETWEEN '".$duration['start_time']."' AND '".$duration['end_time']."' ";
		
		$query_str = 
"SELECT count(*) as counter,date_format(retrieve_time,'%Y-%m-%d') as day 
FROM retrieve 
WHERE ".$filterstr_time.
"GROUP BY date_format(retrieve_time,'%Y-%m-%d')
ORDER BY day ASC";

		$db_result = mysql_query($query_str);
		DEBUGINFO($query_str."\r\n"."Num of result(rows) is ".mysql_num_rows($db_result)."\r\n");
		
		$statistics_map = array();
		while($row = mysql_fetch_array($db_result)){
			$statistics_map[$row['day']] = $row['counter'];
		}
		
		foreach($statistics_map as $key=>$value)
		{
			$result[$key] = $value;
		}		
	}else if(0 == strcmp("month", $duration['interval_type'])){
		$filterstr_time = " retrieve_time BETWEEN '".$duration['start_time']."' AND '".$duration['end_time']."' ";
		
		$query_str = 
"SELECT count(*) as counter,date_format(retrieve_time,'%b') as month 
FROM retrieve 
WHERE ".$filterstr_time.
"GROUP BY date_format(retrieve_time,'%b')
ORDER BY month ASC";

		$db_result = mysql_query($query_str);
		DEBUGINFO($query_str."\r\n"."Num of result(rows) is ".mysql_num_rows($db_result)."\r\n");
		
		$statistics_map = array();
		while($row = mysql_fetch_array($db_result)){
			$statistics_map[$row['month']] = $row['counter'];
		}
		
		foreach($statistics_map as $key=>$value)
		{
			$result[$key] = $value;
		}		
	}
	mysql_close($con);
	return $result;
}


/*统计num个，然后剩余项求和到“其他”*/
/*输出关联数组，每个数组元素形如："皮蛋瘦肉粥"=>20*/
function GetProductMaxs($num, $statinfo, $userinfo){
	$con = mysql_connect("127.0.0.1","root","redhat");
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("test", $con);
	mysql_query("set names utf8");

	/*过滤条件（注意两边加空格）*/
	$filterstr_time = " AND buytime BETWEEN '".$statinfo['start_time']."' AND '".$statinfo['end_time']."' ";
	
	if(null != $userinfo['start_time'] && null != $userinfo['end_time']){
		$filterstr_user = " AND jointime BETWEEN '".$userinfo['start_time']."' AND '".$userinfo['end_time']."' ";
	}
	if(null != $userinfo['fromage'] && null != $userinfo['toage']){
		$filterstr_user = $filterstr_user." AND age BETWEEN ".$userinfo['fromage']." AND ".$userinfo['toage']." ";
	}
	if(1==$userinfo['sex'] || 2==$userinfo['sex']){
		$filterstr_user = $filterstr_user." AND sex=".$userinfo['sex']." ";
	}
	
	$query_str = 
"SELECT orderinfo.menuid, menuname, SUM(amount) sum 
FROM orderinfo,kfcmenu,orders,customers  
where orderinfo.orderid = orders.orderid and orderinfo.menuid=kfcmenu.menuid and customers.openid=orders.openid".$filterstr_time.$filterstr_user.
"GROUP BY menuid 
ORDER BY amount DESC";
	DEBUGINFO($query_str."\r\n\r\n");
	$db_result = mysql_query($query_str);

	$result = array();
	$i = 0;
	while($row = mysql_fetch_array($db_result))
	{
		if($i < $num){
			$result[$row['menuname']] = $row['sum'];
		}else{
			$result['其他'] += $row['sum'];
		}
		$i++;
	}

	mysql_close($con);
	return $result;
}

/*scorelist是数组，传入数据值；abellist是数组，传入scorelist对应的名称；title传入标题*/
function WxDrawPie($___scoreList,$___labelList,$___title)
{	
	/* Create and populate the pData object */
	$MyData = new pData();
	$MyData->addPoints($___scoreList,"ScoreA");  
	$MyData->setSerieDescription("ScoreA","Application A");

	/* Define the absissa serie */
	$MyData->addPoints($___labelList,"Labels");
	$MyData->setAbscissa("Labels");

	/* Create the pChart object */
	$myPicture = new pImage(300*WX_SCALE,260*WX_SCALE,$MyData);

	/* Draw a solid background */
	$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
	$myPicture->drawFilledRectangle(0,0,300*WX_SCALE,260*WX_SCALE,$Settings);

	/* Overlay with a gradient */
	$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
	$myPicture->drawGradientArea(0,0,300*WX_SCALE,260*WX_SCALE,DIRECTION_VERTICAL,$Settings);
	$myPicture->drawGradientArea(0,0,300*WX_SCALE,20*WX_SCALE,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>100));

	/* Add a border to the picture */
	$myPicture->drawRectangle(0,0,299*WX_SCALE,259*WX_SCALE,array("R"=>0,"G"=>0,"B"=>0));

	/* Write the picture title */ 
	$myPicture->setFontProperties(array("FontName"=>WX_FONT,"FontSize"=>14));
	$myPicture->drawText(10*10*WX_SCALE,15*WX_SCALE,$___title,array("R"=>255,"G"=>255,"B"=>255));

	/* Set the default font properties */ 
	$myPicture->setFontProperties(array("FontName"=>WX_FONT,"FontSize"=>10,"R"=>80,"G"=>80,"B"=>80));

	/* Enable shadow computing */ 
	$myPicture->setShadow(TRUE,array("X"=>2,"Y"=>2,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>50));

	/* Create the pPie object */ 
	$PieChart = new pPie($myPicture,$MyData);

	/* Draw an AA pie chart */ 
	$PieChart->draw2DRing(160*WX_SCALE,140*WX_SCALE,array("WriteValues"=>PIE_VALUE_PERCENTAGE,"OuterRadius"=>60*WX_SCALE,"InnerRadius"=>30*WX_SCALE,"ValueR"=>255,"ValueG"=>255,"ValueB"=>255,"Border"=>TRUE));

	/* Write the legend box */ 
	$myPicture->setShadow(FALSE);
	$PieChart->drawPieLegend(15*WX_SCALE,40*WX_SCALE,array("Alpha"=>20));

	/* Render the picture (choose the best way) */
	$myPicture->autoOutput("pictures/example.draw2DRingValue.png");
}

function WxDrawPie3D($___scoreList,$___labelList,$___title)
{
	/* Create and populate the pData object */
	$MyData = new pData();   
	$MyData->addPoints($___scoreList,"ScoreA");  
	$MyData->setSerieDescription("ScoreA","Application A");

	/* Define the absissa serie */
	$MyData->addPoints($___labelList,"Labels");
	$MyData->setAbscissa("Labels");

	/* Create the pChart object */
	$myPicture = new pImage(300*WX_SCALE,260*WX_SCALE,$MyData);

	/* Draw a solid background */
	$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
	$myPicture->drawFilledRectangle(0,0,300*WX_SCALE,300*WX_SCALE,$Settings);

	/* Overlay with a gradient */
	$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
	$myPicture->drawGradientArea(0,0,300*WX_SCALE,260*WX_SCALE,DIRECTION_VERTICAL,$Settings);
	$myPicture->drawGradientArea(0,0,300*WX_SCALE,20*WX_SCALE,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>100));

	/* Add a border to the picture */
	$myPicture->drawRectangle(0,0,299*WX_SCALE,259*WX_SCALE,array("R"=>0,"G"=>0,"B"=>0));

	/* Write the picture title */ 
	$myPicture->setFontProperties(array("FontName"=>WX_FONT,"FontSize"=>12));
	$myPicture->drawText(10*10*WX_SCALE,13*WX_SCALE,$___title,array("R"=>255,"G"=>255,"B"=>255));

	/* Set the default font properties */ 
	$myPicture->setFontProperties(array("FontName"=>WX_FONT,"FontSize"=>10,"R"=>80,"G"=>80,"B"=>80));

	/* Create the pPie object */ 
	$PieChart = new pPie($myPicture,$MyData);

	/* Draw an AA pie chart */ 
	$PieChart->draw3DPie(160*WX_SCALE,160*WX_SCALE,array("Radius"=>70*WX_SCALE,"DrawLabels"=>TRUE,"LabelStacked"=>TRUE,"Border"=>TRUE,"WriteValues"=>PIE_VALUE_PERCENTAGE, "DataGapAngle"=>10));

	/* Write the legend box */ 
	$myPicture->setShadow(FALSE);
	$PieChart->drawPieLegend(15*WX_SCALE,40*WX_SCALE,array("Alpha"=>20));

	/* Render the picture (choose the best way) */
	$myPicture->autoOutput("pictures/example.draw3DPie.labels.png");
	DEBUGINFO("Exit chart process...".microtime(true)."\r\n");
}

function WxDrawLine($scoreList,$serieName,$xLabelList,$yTitle,$topTitle)
{
	/* Create and populate the pData object */
	$MyData = new pData();  
	$MyData->addPoints($scoreList,$serieName);
	$MyData->setSerieWeight($serieName,2);
	$MyData->setAxisName(0,$yTitle);
	$MyData->addPoints($xLabelList,"Labels");
	$MyData->setSerieDescription("Labels","Months");
	$MyData->setAbscissa("Labels");

	/* Create the pChart object */
	$myPicture = new pImage(700*WX_SCALE,230*WX_SCALE,$MyData);

	/* Turn of Antialiasing */
	$myPicture->Antialias = FALSE;

	/* Draw the background */
	$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
	$myPicture->drawFilledRectangle(0,0,700*WX_SCALE,230*WX_SCALE,$Settings);

	/* Overlay with a gradient */
	$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
	$myPicture->drawGradientArea(0,0,700*WX_SCALE,230*WX_SCALE,DIRECTION_VERTICAL,$Settings);
	$myPicture->drawGradientArea(0,0,700*WX_SCALE,20*WX_SCALE,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));

	/* Add a border to the picture */
	$myPicture->drawRectangle(0,0,699*WX_SCALE,229*WX_SCALE,array("R"=>0,"G"=>0,"B"=>0));

	/* Write the chart title */ 
	$myPicture->setFontProperties(array("FontName"=>WX_FONT,"FontSize"=>8,"R"=>255,"G"=>255,"B"=>255));
	$myPicture->drawText(10*WX_SCALE,16*WX_SCALE,$topTitle,array("FontSize"=>14,"Align"=>TEXT_ALIGN_BOTTOMLEFT));

	/* Set the default font */
	$myPicture->setFontProperties(array("FontName"=>WX_FONT,"FontSize"=>12,"R"=>0,"G"=>0,"B"=>0));

	/* Define the chart area */
	$myPicture->setGraphArea(60,40,650*WX_SCALE,200*WX_SCALE);

	/* Draw the scale */
	$scaleSettings = array("XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);
	$myPicture->drawScale($scaleSettings);

	/* Turn on Antialiasing */
	$myPicture->Antialias = TRUE;

	/* Enable shadow computing */
	$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));

	/* Draw the line chart */
	$myPicture->drawLineChart();
	$myPicture->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80));

	/* Write the chart legend 
	$myPicture->drawLegend(590,9,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL,"FontR"=>255,"FontG"=>255,"FontB"=>255));*/

	/* Render the picture (choose the best way) */
	$myPicture->autoOutput("pictures/example.drawLineChart.plots.png");
}

function WxDrawBar($scoreList,$serieName,$xLabelList,$yTitle,$topTitle)
{
	/*$MyData = new pData();  
	$MyData->addPoints($scoreList,$serieName);
	$MyData->setAxisName(0,"Temperatures");
	$MyData->addPoints(array("Jan","Feb","Mar","Apr","May","Jun"),"Labels");
	$MyData->setSerieDescription("Labels","Months");
	$MyData->setAbscissa("Labels");*/
	$MyData = new pData();  
	$MyData->addPoints($scoreList,$serieName);
	$MyData->setAxisName(0,$yTitle);
	$MyData->addPoints($xLabelList,"Labels");
	$MyData->setSerieDescription("Labels","Months");
	$MyData->setAbscissa("Labels");

	/* Create the pChart object */
	$myPicture = new pImage(950*WX_SCALE,230*WX_SCALE,$MyData);

	/* Draw the background */
	$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
	$myPicture->drawFilledRectangle(0,0,950*WX_SCALE,230*WX_SCALE,$Settings);

	/* Overlay with a gradient */
	$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
	$myPicture->drawGradientArea(0,0,950*WX_SCALE,230*WX_SCALE,DIRECTION_VERTICAL,$Settings);
	$myPicture->drawGradientArea(0,0,950*WX_SCALE,20*WX_SCALE,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));

	/* Add a border to the picture */
	$myPicture->drawRectangle(0,0,949*WX_SCALE,229*WX_SCALE,array("R"=>0,"G"=>0,"B"=>0));

	/* Write the picture title */ 
	$myPicture->setFontProperties(array("FontName"=>WX_FONT,"FontSize"=>16));
	$myPicture->drawText(20,35,$topTitle,array("R"=>255,"G"=>255,"B"=>255));

	/* Write the chart title  
	$myPicture->setFontProperties(array("FontName"=>WX_FONT,"FontSize"=>12));
	$myPicture->drawText(250,55,$topTitle,array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));*/

	/* Draw the scale and the 1st chart */
	$myPicture->setGraphArea(60,60,900*WX_SCALE,200*WX_SCALE);
	$myPicture->drawFilledRectangle(60,60,900*WX_SCALE,200*WX_SCALE,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
	$myPicture->drawScale(array("DrawSubTicks"=>TRUE));
	$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
	$myPicture->setFontProperties(array("FontName"=>WX_FONT,"FontSize"=>12));
	$myPicture->drawBarChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO,"Rounded"=>TRUE,"Surrounding"=>30));
	$myPicture->setShadow(FALSE);

	/* Draw the scale and the 2nd chart 
	$myPicture->setGraphArea(500,60,670,190);
	$myPicture->drawFilledRectangle(500,60,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
	$myPicture->drawScale(array("Pos"=>SCALE_POS_TOPBOTTOM,"DrawSubTicks"=>TRUE));
	$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
	$myPicture->drawBarChart();
	$myPicture->setShadow(FALSE);*/

	/* Write the chart legend 
	$myPicture->drawLegend(510,50,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));*/

	/* Render the picture (choose the best way) */
	$myPicture->autoOutput("pictures/example.drawBarChart.png");
}

function DEBUGINFO($abc)
{
	@ $fp = fopen("debugchart.txt", 'ab');
	fwrite($fp, $abc);
	fclose($fp);
}

?>


